//
//  ShopCartGoodsListTool.m
//  LoveFreshBeen
//
//  Created by 胡不归是大虾 on 2016/10/19.
//  Copyright © 2016年 魏根. All rights reserved.
//

#import "ShopCartGoodsListTool.h"
#import "HMHomeFirstModel.h"
@implementation ShopCartGoodsListTool
+(ShopCartGoodsListTool*)sharedGoodsListTool{
    static ShopCartGoodsListTool* tool ;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
         tool = [[ShopCartGoodsListTool alloc] init];
    });
    return tool;
}
-(void)addGoodsToShopCartGoodsList:(HMHomeFirstModel*)model{
    //判断是否已包含
    if ([self.goodsList containsObject:model]) {
        return;
    }
    [self.goodsList addObject:model];
}
-(void)reduceGoodsFromShopCartGoodsList:(HMHomeFirstModel*)model{
    //判断是否包含
    if ([self.goodsList containsObject:model]) {
        if (model.goodsCount == 0) {
            [self.goodsList removeObject:model];
        }
    }
}

- (NSInteger)goodCount{
    
   __block NSInteger count = 0;
    [[self goodsList]enumerateObjectsUsingBlock:^(HMHomeFirstModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        count += obj.goodsCount;
    }];
    return count;
}

-(NSMutableArray *)goodsList{
    if (_goodsList == nil) {
        _goodsList = [NSMutableArray array];
    }
    return _goodsList;
}
@end
